#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int maxHeightOfTriangle(int red, int blue) {
        int red1 = red, red2 = red;
        int blue1 = blue, blue2 = blue;
        int i = 0;
        for (i = 1; (blue1 >= 0 && red1 >= 0) || (blue2 >= 0 && red2 >= 0); ++i)
        {
            if (i % 2 == 0)
            {
                red1 -= i;
                blue2 -= i;
            }
            else
            {
                red2 -= i;
                blue1 -= i;
            }
        }

        return i - 2;
    }
};